#
# @lc app=leetcode.cn id=38 lang=python3
#
# [38] 报数
#

# @lc code=start
class Solution:
    def countAndSay(self, n):
        pre = '1'
        for i in range(1, n):
            next_num, num, count = '', pre[0], 1
            for j in range(1, len(pre)):
                if pre[j] == num: 
                    count += 1
                else:
                    next_num += str(count) + num
                    num = pre[j]
                    count = 1
            next_num += str(count) + num
            pre = next_num
        return pre

            
# @lc code=end

